package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.*


import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/3
 * 时间：17:04
 * 包名：com.vitabuybuy.tv.network
 */
object MineRepository {

    fun getInfoByToken(): IAwait<LoginInfoDto> {
        return RxHttp.postJson(NetUrl.api_getinfo_by_token).toResponse()
    }
    fun getOrderCount(): IAwait<OrderCountDto> {
        return RxHttp.postJson(NetUrl.api_order_count).toResponse()
    }

    fun userSign(): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_user_sign).toResponse()
    }

    fun userIsSign(): IAwait<UserSingRecordDto> {
        return RxHttp.postJson(NetUrl.api_sign_record).toResponse()
    }
    fun getActivityRewards(): IAwait<List<ActivityUserRecordDto>> {
        return RxHttp.postJson(NetUrl.api_activity_list).toResponse()
    }

    fun resetUserInfo(key: String, value: Any?): IAwait<String> {
        val map = if (key == "regionId") {
            mapOf(Pair("region", mapOf(Pair("id", value))))
        } else {
            mapOf(Pair(key, value))
        }
        return RxHttp.postJson(NetUrl.api_reset_user_info)
            .add("user", map)
            .add("client", "app").toResponse()
    }

    fun getMyFollowList(
        type: String,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<MyFollowListDto>> {
        val params = mapOf(
            Pair("type", type),
            Pair(
                "pageable",
                mapOf(
                    Pair("page", pageNumber),
                    Pair("size", pageSize),
                    Pair("desc", "id")
                )
            )
        )
        return RxHttp.postJson(NetUrl.api_my_follow)
            .addAll(params).toResponse()
    }

    fun getMyCollectList(
        type: String,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<MyCollectListDto>> {
        val params = mapOf(
            Pair("type", type),
            Pair(
                "pageable",
                mapOf(
                    Pair("page", pageNumber),
                    Pair("size", pageSize),
                    Pair("desc", "id")
                )
            )
        )

        return RxHttp.postJson(NetUrl.api_my_collect)
            .addAll(params).toResponse()
    }

    fun collectOrcancelMore(idList: ArrayList<Int>): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_delete_collect_more)
            .add("idList", idList).toResponse()
    }


    fun getFootPrint(
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<MyFootPrintListDto>> {
        val params = mapOf(
            Pair(
                "pageable",
                mapOf(
                    Pair("page", pageNumber),
                    Pair("size", pageSize),
                    Pair("desc", "id")
                )
            )
        )
        return RxHttp.postJson(NetUrl.api_get_foot_print_list)
            .addAll(params).toResponse()
    }

    fun deleteFootPrint(id: Int): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_delete_foot_print).add("id", id).toResponse()

    }
}